package test.example.controller.ajax.user.authenticated;

import javax.servlet.http.HttpServletResponse;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public abstract class AuthenticatedControllerBase extends Controller {
    
    
    @Override
    public Navigation run() throws Exception {
        
        UserService userService = UserServiceFactory.getUserService();
        String thisURL = request.getRequestURI();
        if (request.getUserPrincipal() != null) {
            // ログインしている場合の処理
            requestScope("loginInfo", "<p>You can <a href=\"" +
                userService.createLogoutURL(thisURL) +
                "\">sign out</a>.</p>");
            // 他の処理
        } else {
            // ログインしていない場合の処理
            //ログアウトURLに転送
            ((HttpServletResponse) response).sendRedirect(userService
                .createLoginURL("/"));
        }
        return runAfterAuth();
    }
    
    public abstract Navigation runAfterAuth();
    
    
    

}
